﻿using UnityEngine;

namespace HKTools
{
    /// <summary>
    /// 摄像机多目标切换管理工具，HK_FollowTargetItem 控制脚本
    /// </summary>
    public class HK_FollowTarget : HK_BaseTarget
    {
        public Vector3 TargetPos
        {
            get { return transform.position + transform.forward * distance; }
        }

        public Vector3 TargetDir
        {
            get { return transform.position - TargetPos; }
        }

        [Header("默认距离（Green）：")]
        public float distance = 2;
        [Header("最近距离（Blue）：")]
        public float minDis;
        [Header("最远距离（Red）：")]
        public float maxDis;

        public override void Awake()
        {
            base.Awake();
            TargetKind = HK_TargetKind.FollowTarget;
        }

        // 绿色为默认目标位置，红色为最远位置，蓝色为最近位置
        void OnDrawGizmosSelected()
        {
            var radius = 1f;

            if (minDis > distance)
                minDis = distance;

            Gizmos.color = Color.blue;
            Gizmos.DrawRay(transform.position, transform.forward * minDis);
            Gizmos.DrawSphere(transform.position + transform.forward * minDis, radius);

            Gizmos.color = Color.green;
            Gizmos.DrawRay(transform.position + transform.forward * minDis, transform.forward * (distance - minDis));
            Gizmos.DrawSphere(transform.position + transform.forward * distance, radius);

            if (maxDis < distance)
                maxDis = distance;

            Gizmos.color = Color.red;
            Gizmos.DrawRay(transform.position + transform.forward * distance, transform.forward * (maxDis - distance));
            Gizmos.DrawSphere(transform.position + transform.forward * maxDis, radius);
        }
    }
}